/**
 * Created by 小敏哥on 2017/3/8.
 */
import {
    COUPON_LIST,
    PROCE_DURES
} from "./actionsTypes"
import {Toast} from 'antd-mobile';

import couponService from '../services/couponService';

export const couponList = data => ({ type: COUPON_LIST, data:data }); //

export const proceDures = data => ({ type: PROCE_DURES, data:data });

export const getCouponList=(data,callBack)=>{
    return (dispatch, getState) => {
        Toast.hide(); //加载前 先关闭其他加载中的提示框 避免提示框一直存在的bug
        Toast.loading("", 30, () => Toast.info("网络错误", 2));
        couponService.getCouponList(data).then(resultData=>{
            Toast.hide();
            if (resultData.code == 1000) {
                dispatch(couponList(resultData.data.couponList));
                callBack&&callBack();
            }
            else{
                Toast.info(resultData.msg, 2);
            }
        });
/*        dispatch(couponList( [
                {
                    title: "驾驶换证办理优惠券1",
                    time: "2016-12-1",
                    amount: "100"
                },
                {
                    title: "驾驶换证办理优惠券2",
                    time: "2016-12-2",
                    amount: "200"
                },
                {
                    title: "驾驶换证办理优惠券3",
                    time: "2016-12-3",
                    amount: "300"
                },
                {
                    title: "驾驶换证办理优惠券4",
                    time: "2016-12-4",
                    amount: "20"
                }
            ]
        ))*/
    }
}
